AngularJS uses ng repeat to report errors [ngRepeat: dupes]

  • 2021-07-12 05:18:28
  • OfStack

AngularJS uses ng-repeat to report errors

[ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify uniq

ng-repeat error report


   
<div ng-init="words = [' Colleges and universities ',' Colleges and universities ',' Colleges and universities ']" ng-repeat="word in words"> 
  {{word}} 
</div> 

[ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys

Discovery is caused by duplication of the same content, and solutions


<div ng-init="words = [' Colleges and universities ',' Colleges and universities ',' Colleges and universities ']" ng-repeat="word in words track by $index"> 
  {{word}} 
</div> 

Add after ng-repeat


track by $index 

Thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: